function rand(min,max) {
    var result = Math.floor(Math.random() * (max+1));
    if(result < min){
        return rand(min,max);
    } else {
        return result;
    }
}

var _ = {
		"uid":rand(500,1500),
		"modulos":[],
		"getUid":function(){
			this.uid++;
			return this.uid;
		},
		"loadModule":function(args){
			var configs = $.extend({"obj":"","mod":"","url":"","act":"","p":[],"puid":""},args);
			if(configs["obj"]==""){
				configs["obj"]=configs["mod"].toLowerCase();
			}			
			if(typeof configs["onLoad"] == "undefined" || typeof configs["onLoad"] == "null"){
				configs["onLoad"] = function(){
					window[configs["obj"]] = {};
					window[configs["obj"]][configs["act"]]=function(){};                
					//window[tela].apply(window[objeto],[]);
					window[configs["obj"]] = new window[configs["mod"]]();   
					window[configs["obj"]]._moduleName = configs["url"];				
					if(configs["act"]!=""){
						window[configs["obj"]][configs["act"]].apply(window[configs["obj"]],configs["p"]);  
					}
	                if(configs["puid"]!=""){
	                	window[configs["obj"]].htmlX.addClass("_"+window[configs["puid"]].uid);
	    				window[configs["obj"]].onlyAppend();
	    				window[configs["obj"]].onlyShow(true);
	                }else{
	                	window[configs["obj"]].show(true,true);
	                }
				};
			}
			if(window[configs["obj"]]){
				window[configs["obj"]]._moduleName = configs["url"];
								
				if(configs["act"]!=""){
					window[configs["obj"]][configs["act"]].apply(window[configs["obj"]],configs["p"]);  
				}
				if(configs["puid"]==""){
                	window[configs["obj"]].show(true,true);
                }else{
                	window[configs["obj"]].onlyShow(true);
                }				
			}else{
				$.getScript(configs["url"],configs["onLoad"]);            
			}      
		},
		"getUrlParam":function(pname){
			var results = new RegExp('[\?&]' + pname + '=([^&#]*)').exec(window.location.href);
			if (results==null){
			   return "";
			}else{
			   return results[1] || "";
			}	
		},		
		"loadPrintLibs":function(){
			if(!window["jsPDF"]){
				$.getScript('lib/jspdf/libspdf.js');
			};
			if(!window["pdfpreview"]){
				window["pdfpreview"] = new PdfPreview();		
			};
		},
		"printDataProvider":function(p_dta,template){
			_.loadPrintLibs();
			$.getJSON(template,function(dtaj){
			 	dtaj["dataSets"][0]["itens"]  = p_dta;
				var pdf = new jsPDF('p','pt','a4');		
				pdf.setJereport(dtaj);
				pdfpreview.setReportPreview(pdf.output('datauristring'));
				pdfpreview.show(true,true);
				//liberando a memoria
				p_dta = null;
				dtaj = null; 
			});
		},
};